package com.joke.mydiary.DaoImpl;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * 数据库助手类
 * Created by Administrator on 2015/11/30.
 */
public class DatabaseHelper extends SQLiteOpenHelper {
    private static final int VERSION = 1;
    private static final String DB_NAME = "diary.db";
    private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS diaries(_id INTEGER PRIMARY KEY AUTOINCREMENT," +
            "date TIMESTAMP ," +
            "content TEXT," +
            "image_path TEXT)";
    private static final String DROP_TABLE = "DROP TABLE IF EXISTS diaries";

    /**
     * 用于创建数据库
     *
     * @param context
     *
     */
    public DatabaseHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(CREATE_TABLE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL(DROP_TABLE);
        db.execSQL(CREATE_TABLE);
    }
}
